package com.lee.common.adapter.binding

import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.databinding.ViewDataBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder

/**
 *
 */
abstract class BaseDataBindingAdapter<T, Binding : ViewDataBinding> :
    BaseQuickAdapter<T, BaseDataBindingHolder<Binding>> {

    constructor(@LayoutRes layoutResId: Int, data: MutableList<T>?) : super(layoutResId, data)

    constructor(@LayoutRes layoutResId: Int) : super(layoutResId)

    override fun onCreateDefViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): BaseDataBindingHolder<Binding> {
        return super.onCreateDefViewHolder(parent, viewType)
    }

    override fun convert(holder: BaseDataBindingHolder<Binding>, item: T) {
        val binding= holder.dataBinding
        binding?.also {
            convert(it, item)
            it.executePendingBindings()
        }
    }

    protected abstract fun convert(binding: Binding, item: T)


}
